﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>


<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.18/dist/css/layui.css" rel="stylesheet">
</head>
<body>

    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <div class="layui-form-item">
                        <label class="layui-form-label">企业全称</label>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="companieFullName" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">企业简称</label>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="bbb" class="layui-input">
                        </div>
                    </div>
                    <div>
                        <label class="layui-form-label">企业Logo</label>
                        <button type="button" class="layui-btn" id="ID-upload-demo-btn">
                            <i class="layui-icon layui-icon-upload"></i> 上传
                        </button>
                        <div style="width: 132px">
                            <div class="layui-upload-list">
                                <img class="layui-upload-img" id="ID-upload-demo-img" style="width: 100%; height: 92px;">
                                <div id="ID-upload-demo-text"></div>
                            </div>
                            <div class="layui-progress layui-progress-big" lay-showPercent="yes" lay-filter="filter-demo">
                                <div class="layui-progress-bar" lay-percent=""></div>
                            </div>
                        </div>

                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">行业标签</label>
                        <div class="layui-input-inline">
                            <select id="yiji" lay-filter="aihao">
                                <option value="">请选择</option>
                                <option value="1">养殖业</option>
                                <option value="2">种植业</option>
                                <option value="3">投入品</option>
                                <option value="4">大田农资</option>
                                <option value="5">农产品加工</option>

                            </select>
                        </div>
                        <div class="layui-input-inline">

                            <select id="secondLevelId" lay-filter="aihao">
                                <option value="">请选择</option>
                                <option value="1">生猪</option>
                                <option value="2">肉牛</option>
                                <option value="3">奶牛</option>
                                <option value="4">肉羊</option>
                                <option value="5">奶羊</option>
                            </select>

                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">所在区域</label>
                        <div class="layui-input-inline">
                            <select id="provinceId" lay-filter="provincet">
                                <option value="">请选择</option>
                            </select>
                        </div>
                        <div class="layui-input-inline">
                            <select id="directlyId" lay-filter="city">
                                <option value="">请选择</option>
                            </select>
                        </div>

                        <div class="layui-input-inline">
                            <select id="countyId" lay-filter="directly">
                                <option value="">请选择</option>
                            </select>
                        </div>

                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">详细地址</label>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="fullAddress" class="layui-input">
                        </div>
                        <div style="width:400px;height:300px;border:#ccc solid 1px;" id="dituContent"></div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">企业电话</label>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="companiePhone" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">统一社会信用代码</label>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="creditCode" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">描述</label>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="companieDesc" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">停用企业</label>
                        <div class="layui-input-block">
                            <input type="radio" name="DeactivateCompanie" value="true" checked title="启用">
                            <input type="radio" name="DeactivateCompanie" value="false" title="停用">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">负责人</label>
                        <div class="layui-input-block">
                            <select id="head" lay-filter="aihao">
                                <option value="">请选择</option>
                                <option value="李炳峰">李炳峰</option>
                                <option value="李辉">李辉</option>
                                <option value="李体验">李体验</option>
                                <option value="李艳芬">李艳芬</option>
                                <option value="刘超">刘超</option>
                                <option value="刘明">刘明</option>
                                <option value="刘瑞">刘瑞</option>
                                <option value="刘震">刘震</option>
                                <option value="陆雪琪">陆雪琪</option>
                            </select>
                        </div>

                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">财务负责人</label>
                        <div class="layui-input-block">
                            <select id="financeHead" lay-filter="aihao">
                                <option value="">请选择</option>
                                <option value="李炳峰">李炳峰</option>
                                <option value="李辉">李辉</option>
                                <option value="李体验">李体验</option>
                                <option value="李艳芬">李艳芬</option>
                                <option value="刘超">刘超</option>
                                <option value="刘明">刘明</option>
                                <option value="刘瑞">刘瑞</option>
                                <option value="刘震">刘震</option>
                                <option value="陆雪琪">陆雪琪</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">分管负责人</label>
                        <div class="layui-input-block">
                            <select id="inChargeHead" lay-filter="aihao">
                                <option value="">请选择</option>
                                <option value="李炳峰">李炳峰</option>
                                <option value="李辉">李辉</option>
                                <option value="李体验">李体验</option>
                                <option value="李艳芬">李艳芬</option>
                                <option value="刘超">刘超</option>
                                <option value="刘明">刘明</option>
                                <option value="刘瑞">刘瑞</option>
                                <option value="刘震">刘震</option>
                                <option value="陆雪琪">陆雪琪</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">可查看人员</label>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="viewablePersonnel" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">核算单元</label>
                        <div id="ID-tree-demo-showLine"></div><input type="text" id="accountingUnitId" class="layui-input">
                        <div class="layui-input-inline layui-input-wrap">
                            
                        </div>

                        @* <div class="layui-input-inline layui-input-wrap">
                            
                        </div> *@
                    </div>
                    <input type="button" class="layui-btn" lay-submit lay-filter="demo1" onclick="add()" value="保存" />

                </div>
            </div>
        </div>
    </form>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=rp5j6DYVV8tDQoOMrbQgAFxrAwnKvcWM"></script>
</body>

</html>

<script>

    //创建和初始化地图函数：
    function initMap() {
        createMap();//创建地图
        setMapEvent();//设置地图事件
        addMapControl();//向地图添加控件
        addMarker();//向地图中添加marker
    }

    //创建地图函数：
    function createMap() {
        var map = new BMap.Map("dituContent");//在百度地图容器中创建一个地图
        var point = new BMap.Point(116.403963, 39.915119);//定义一个中心点坐标
        map.centerAndZoom(point, 17);//设定地图的中心点和坐标并将地图显示在地图容器中
        window.map = map;//将map变量存储在全局
    }

    //地图事件设置函数：
    function setMapEvent() {
        map.enableDragging();//启用地图拖拽事件，默认启用(可不写)
        map.enableScrollWheelZoom();//启用地图滚轮放大缩小
        map.enableDoubleClickZoom();//启用鼠标双击放大，默认启用(可不写)
        map.enableKeyboard();//启用键盘上下左右键移动地图
    }

    //地图控件添加函数：
    function addMapControl() {
        //向地图中添加缩放控件
        var ctrl_nav = new BMap.NavigationControl({ anchor: BMAP_ANCHOR_TOP_LEFT, type: BMAP_NAVIGATION_CONTROL_LARGE });
        map.addControl(ctrl_nav);
        //向地图中添加缩略图控件
        var ctrl_ove = new BMap.OverviewMapControl({ anchor: BMAP_ANCHOR_BOTTOM_RIGHT, isOpen: 1 });
        map.addControl(ctrl_ove);
        //向地图中添加比例尺控件
        var ctrl_sca = new BMap.ScaleControl({ anchor: BMAP_ANCHOR_BOTTOM_LEFT });
        map.addControl(ctrl_sca);
    }

    //标注点数组
    var markerArr = [{ title: "我的标记", content: "我的备注", point: "116.403936|39.915147", isOpen: 0, icon: { w: 21, h: 21, l: 0, t: 0, x: 6, lb: 5 } }
    ];
    //创建marker
    function addMarker() {
        for (var i = 0; i < markerArr.length; i++) {
            var json = markerArr[i];
            var p0 = json.point.split("|")[0];
            var p1 = json.point.split("|")[1];
            var point = new BMap.Point(p0, p1);
            var iconImg = createIcon(json.icon);
            var marker = new BMap.Marker(point, { icon: iconImg });
            var iw = createInfoWindow(i);
            var label = new BMap.Label(json.title, { "offset": new BMap.Size(json.icon.lb - json.icon.x + 10, -20) });
            marker.setLabel(label);
            map.addOverlay(marker);
            label.setStyle({
                borderColor: "#808080",
                color: "#333",
                cursor: "pointer"
            });

            (function () {
                var index = i;
                var _iw = createInfoWindow(i);
                var _marker = marker;
                _marker.addEventListener("click", function () {
                    this.openInfoWindow(_iw);
                });
                _iw.addEventListener("open", function () {
                    _marker.getLabel().hide();
                })
                _iw.addEventListener("close", function () {
                    _marker.getLabel().show();
                })
                label.addEventListener("click", function () {
                    _marker.openInfoWindow(_iw);
                })
                if (!!json.isOpen) {
                    label.hide();
                    _marker.openInfoWindow(_iw);
                }
            })()
        }
    }
    //创建InfoWindow
    function createInfoWindow(i) {
        var json = markerArr[i];
        var iw = new BMap.InfoWindow("<b class='iw_poi_title' title='" + json.title + "'>" + json.title + "</b><div class='iw_poi_content'>" + json.content + "</div>");
        return iw;
    }
    //创建一个Icon
    function createIcon(json) {
        var icon = new BMap.Icon("http://app.baidu.com/map/images/us_mk_icon.png", new BMap.Size(json.w, json.h), { imageOffset: new BMap.Size(-json.l, -json.t), infoWindowOffset: new BMap.Size(json.lb + 5, 1), offset: new BMap.Size(json.x, json.h) })
        return icon;
    }

    initMap();//创建和初始化地图


</script>
<script>
    var upland = "";

    layui.use(function () {
        var form = layui.form;
        // var $ = layui.jquery;
        var tree = layui.tree;
        var upload = layui.upload;
        var layer = layui.layer;
        var element = layui.element;
        var $ = layui.$;
        $(function () {
            bangsheng();
        })
        var datas = [];
        function treeList() {

            $.post({
                url: "http://localhost:5123/api/Flats/AccountingUnitQuery",

                data: JSON.stringify({}),
                dataType: "json",
                contentType: "application/json",
                success: d => {
                    datas = d.data;
                    console.log(datas);
                    tree.render({
                        elem: '#ID-tree-demo-showLine',
                        data: datas,
                        showLine: false , // 是否开启连接线
                        click: function (res) {
                            $("#accountingUnitId").val(JSON.stringify(res.data.value));
                            console.log(res)
                        }
                    });
                }
            })
        }

        // 渲染
        treeList();

        function bangsheng() {
            $.ajax({
                url: "http://localhost:5123/api/Regions/ProvinceQuerys",
                data: JSON.stringify({}),
                type: "post",
                async: false,
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    console.log(res)
                    $.each(res.data, function () {
                        $("#provinceId").append(`<option value="${this.provinceId}">${this.provinceName}</option>`);
                    })
                    form.render('select'); // 重新渲染下拉框
                }

            })
        }
        var provincetId1 = 0;
        var cityid = 0;
        form.on('select(provincet)', function (data) {
            provincetId1 = data.value;
            console.log(provincetId1)
            bangshi()

        });
        form.on('select(city)', function (data) {
            cityid = data.value;
            console.log(provincetId1)
            bangxian();

        });

        function bangshi() {
            var provinceId = $("#provinceId").val();
            $.ajax({
                url: "http://localhost:5123/api/Regions/CityQuerys",
                data: JSON.stringify({ provinceId: provincetId1 }),
                type: "post",
                async: false,
                dataType: "json",
                contentType: "application/json",
                success: res => {

                    console.log(res.data)
                    $.each(res.data, function () {
                        $("#directlyId").append(`<option value="${this.directlyId}">${this.directlyName}</option>`);
                    })
                    form.render('select'); // 重新渲染下拉框
                }

            })
        }

        function bangxian() {
            var directlyId = $("#directlyId").val();
            $.ajax({
                url: "http://localhost:5123/api/Regions/CountyQuerys",
                data: JSON.stringify({ directlyId: cityid }),
                type: "post",
                async: false,
                dataType: "json",
                contentType: "application/json",
                success: res => {

                    $.each(res.data, function () {
                        $("#countyId").append(`<option value="${this.countyId}">${this.countyName}</option>`);
                    })
                    form.render('select'); // 重新渲染下拉框
                }

            })
        }

        // 单图片上传
        var uploadInst = upload.render({
            elem: '#ID-upload-demo-btn',
            url: 'http://localhost:5123/api/CommonProvinces/UpLoadFile', // 实际使用时改成您自己的上传接口即可。
            before: function (obj) {
                // 预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#ID-upload-demo-img').attr('src', result); // 图片链接（base64）
                });
                element.progress('filter-demo', '0%'); // 进度条复位
                layer.msg('上传中', { icon: 16, time: 0 });
            },
            done: function (res) {
                // 若上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                // 上传成功的一些操作
                // …
                upland = res.data
                $('#ID-upload-demo-text').html(''); // 置空上传失败的状态
            },
            error: function (err) {
                // 演示失败状态，并实现重传
                var demoText = $('#ID-upload-demo-text');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            },
            // 进度条
            progress: function (n, elem, e) {
                element.progress('filter-demo', n + '%'); // 可配合 layui 进度条元素使用
                if (n == 100) {
                    layer.msg('上传完毕', { icon: 1 });
                }
            }
        });



    });


    function add() {
        var data = {
            companieFullName: $("#companieFullName").val(),
            companieLOGO: upland,
            secondLevelId: $("#secondLevelId").val(),
            provinceId: $("#countyId").val(),
            fullAddress: $("#fullAddress").val(),
            companiePhone: $("#companiePhone").val(),
            creditCode: $("#creditCode").val(),
            companieDesc: $("#companieDesc").val(),
            deactivateCompanie: $("[name=DeactivateCompanie]:checked").val() == "true" ? true : false,
            head: $("#head").val(),
            financeHead: $("#financeHead").val(),
            inChargeHead: $("#inChargeHead").val(),
            viewablePersonnel: $("#viewablePersonnel").val(),
            accountingUnitId: $("#accountingUnitId").val(),
        }
        console.log(data);
       
        $.ajax({
            url: "http://localhost:5123/api/Flats/FlatsAdds",
            type: "post",
            data: JSON.stringify(data),
            dataType: "json",
            contentType: "application/json",
            success: d => {
                if (d == 0) {
                    alert('保存失败');
                }
                else {
                    alert('保存成功');
                }
            }
        })
    }













</script>




